﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace MVCnExt.Web.UI.Ext
{
    public static class GeneralExtensions
    {
        public static string ToExtString(this Object source)
        {
            Regex r = new Regex(@"\b(\w)(\w+)?\b", RegexOptions.Multiline | RegexOptions.IgnoreCase);
            MatchEvaluator ME = new MatchEvaluator(ReplaceM);

            return r.Replace(source.ToString(), ME);
        }

        /// <summary> 
        /// Replace the words with there appriotiriate casing 
        /// </summary> 
        /// <param name="m">regular expression match class</param> 
        /// <returns></returns> 
        public static string ReplaceM(Match m)
        {
            string FirstLetter;
            string Word;
            Word = m.Groups[2].Value;
            FirstLetter = m.Groups[1].Value.ToLower();
            return FirstLetter + Word;
        } 
    }
}
